/*
 * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.net.dreamlu.net).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package netty.mqtt.smoke;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import netty.mqtt.BeverageMixerData;
import netty.mqtt.MqttCommonMsg;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class SmokeData {
    public static void main(String[] args) {
        // 初始化 mqtt 客户端
        MqttClient client = MqttClient.create()
                .ip("127.0.0.1")
                .port(1883)
                .connect();

        ScheduledExecutorService schedule = Executors.newScheduledThreadPool(4);
        schedule.scheduleAtFixedRate(
                new Runnable() {
                    @Override
                    public void run() {
                        try {
                            String ricer = FileUtils.readFileToString(new File("D:\\spring-demo\\tool-example\\src\\main\\java\\netty\\mqtt\\smoke\\ricer.json"),
                                    Charset.defaultCharset());
                            String chainoven = FileUtils.readFileToString(new File("D:\\spring-demo\\tool-example\\src\\main\\java\\netty\\mqtt\\smoke\\chainoven.json"),
                                    Charset.defaultCharset());
                            client.publish("/api/smoke/data", ByteBuffer.wrap(ricer.getBytes()));
                            client.publish("/api/smoke/data", ByteBuffer.wrap(chainoven.getBytes()));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }, 5, 600, TimeUnit.SECONDS);
    }

}
